#!/bin/bash
nginxurl=/opt/openresty/nginx
. $nginxurl/scripts/golo.conf
source  $ROS_ASLAM_WS_PATH
roscd perception_ros/../../../map
mapdir=$(pwd)
asmfile=$(ls /home/nuc/slam_data -t |sed -n '1p')
rosservice call /save_state 0.2
sleep 1
sudo rm  -rf $mapdir/network_data
sleep 3
sudo mv  /home/nuc/slam_data/$asmfile $mapdir/network_data
#while true
#do
#oldoriginsize=`ls -l /home/nuc/slam_data/$asmfile/map_picture.png | awk '{ print $5 }'`
#neworiginsize=`ls -l $mapdir/network_data/map_picture.png | awk '{ print $5 }'`
#if [ $neworiginsize -eq $oldoriginsize ];then
#        break
#fi
 sleep 10
#done
sudo systemctl stop aslamS
cd $mapdir/network_data
sudo sed -i "1s/0,0,0/$1,$2,0/g" origin_info.txt
sudo cp $mapdir/network_data/map_3d.pcd $mapdir/network_data/2024.pcd
sleep 1
sudo systemctl stop aslamS.service ;rosnode kill /mapping_node;echo y |rosnode cleanup
sudo chmod 777 $mapdir/network_data -R
if [ ! -n "$3" ];then
        exit 0
fi
sudo cp -rf $mapdir/network_data $mapdir/$3
while true
do
oldoriginsize=`ls -l $mapdir/network_data/map_picture.png | awk '{ print $5 }'`
neworiginsize=`ls -l $mapdir/$3/map_picture.png | awk '{ print $5 }'`
if [ $neworiginsize -eq $oldoriginsize ];then
        break;sudo chmod 777 $mapdir -R
fi
 sleep 1
done
